<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Preface</title>
</head>
<body>
  <h3>Preface</h3>
<p>Java Persistence API 2.0 specification went final in December 2009. All major players like Hibernate (v3.5), EclipseLink (v2.0) and OpenJPA (v2.0) already support JPA 2.0. When JPA 1.0 came about, being a long term Hibernate user and admirer, I was quite curious about the standardization efforts but was quickly disappointed to find it offer a very limited subset of functionality that was already present in Hibernate. Obvious things that I took for granted, such as Criteria API and component mappings were missing. As a result, I quickly forgot about it and continued happily using Hibernate api. Comparatively, JPA2 looks quite promising and though I suspect, henceforth, the standards will always have to play catch up with the innovations happening outside, we can safely apply the 80-20 rule to JPA2 usage. One can use JPA2 api for most of the day-to-day usage while falling back to Hibernate (or your preferred ORM tool) for any (probably exotic) use cases not supported by JPA2.</p>
<p></p>
<p>Coming to usage of an ORM tool, I'm sure everyone will agree that any non-trivial application will have to deal with relationships between its domain entities. Like in real life, maintaining relationships is certainly not an easy job :-) and can lead to anti-patterns such as mapping components as top-level entities, mapping the association between many-to-many relationship as top level entity so on and so forth. Also, with focus shifting from verbose xml configuration to annotations, my guess is, not many would be as into the JPA2 api and configuration yet as they would be into some ORM tool specific stuff. That's when I thought of creating a simple online reference for mapping relationships using JPA2 api and here we are.
</p>
<p>If you would like to play with the examples yourself, the supporting code is available here -
<a id="downloadlink" href="http://code.google.com/p/learningjpa2/downloads/list">Learning JPA2 Examples Eclipse Project Artefacts</a>
</p>
<p>It's a self-contained Eclipse(Galileo) project that uses Hibernate v3.5 as JPA2 provider and MySQL as database. After downloading, you can directly import it into Eclipse using <em>Import -> Existing Projects into Workspace -> Select archive file</em> option. For some reason, if you would like to use any database other than mysql, drop the jdbc driver jar for your chosen database into lib directory and change the JPA2 configuration in <em>/META-INF/persistence.xml</em> accordingly.</p>
<p>
  The source code for this application as well as the examples is also available on Google Code -
  <a id="sourcelink" href="http://code.google.com/p/learningjpa2">http://code.google.com/p/learningjpa2</a>
</p>
<p>If you have any questions, suggestions or would just like to offer a pint for such an excellent tutorial ;-), feel free to contact me using the details in the footer.
</p>
<p><strong>Note : </strong><em>As of now (June 2010), it's just the beginning and this application doesn't contain pages on all mappings yet, but I intend to build it up progressively by adding at least one page per week henceforth. So, do bookmark it and keep coming back. You can take a look at change log to find newly added topics. Also, newly added topics will sport a tooltip stating as such if you hover over them in the navigation tree.</em></p>
</body>
</html>
